package Operation;

import controller.DataAccessHandler;

import java.util.Scanner;

/**
 * 保存新账户
 */
public class AddNewAccountIOperation implements IOperation {
    @Override
    public void operate() {
        System.out.println("<保存新账户>");
        //输入账户信息
        Scanner keyboardInput = new Scanner(System.in);
        System.out.print("关键字：");
        String keyword = keyboardInput.next();
        System.out.print("账号：");
        String accountNumber = keyboardInput.next();
        System.out.print("密码：");
        String password = keyboardInput.next();
        System.out.print("备注：");
        String remark = keyboardInput.next();

        //访问数据库，执行sql语句
        String sql = "insert into tb_accounts value (null,?,?,?,?,now(),now())";
        boolean isSuccess = DataAccessHandler.update(sql, keyword, accountNumber, password, remark);
        if (isSuccess){
            System.out.println("Saved successfully!");
        }else{
            System.out.println("Failed!");
        }
    }
}
